class AttendeesController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @attendee_pages, @attendees = paginate :attendees, :per_page => 10
  end

  def show
    @attendee = Attendee.find(params[:id])
  end

  def new
    @attendee = Attendee.new 
    @meetings = Meeting.find(:all)
  end

  def create
    @attendee = Attendee.new(params[:attendee])
    if @attendee.save
      flash[:notice] = 'Attendee was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
      @meetings = Meeting.find(:all)      
    end
  end

  def edit
    @attendee = Attendee.find(params[:id])
    @meetings = Meeting.find(:all)
  end

  def update
    @attendee = Attendee.find(params[:id])
    if @attendee.update_attributes(params[:attendee])
      flash[:notice] = 'Attendee was successfully updated.'
      redirect_to :action => 'show', :id => @attendee
    else
      @meetings = Meeting.find(:all)
      render :action => 'edit'
    end
  end

  def destroy
    Attendee.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
